{include file="public/head"}
<style>
    .caozuo .layui-btn {
        margin-left: auto;
    }

    .x-body {
        min-width: 1400px;
    }

    body {
        overflow-x: scroll;
    }
</style>
<body>
<div class="x-body">
    <div class="lotus-nav">
        <div class="layui-input-inline">
            <input id="proname" name="proname" class="layui-input" placeholder="产品标题" value="{$Think.get.proname}">
        </div>

        <div class="layui-input-inline">
            <input id="code" name="code" class="layui-input" placeholder="SKU码" value="{$Think.get.code}">
        </div>

        <div class="layui-input-inline layui-form" style="width: 150px">
            <select name="platform" id="platform" lay-filter="platform">
                <option value="">商品平台</option>
                {volist name="platform" id="vo"}
                <option value="{$vo.english}" {if $Think.get.platform eq $vo['english']} selected {/if}>{$vo.name}</option>
                {/volist}
            </select>
        </div>

        <div class="layui-input-inline layui-form" style="width: 150px">
            <select name="share" id="share">
                <option value="">数据来源</option>
                <option value="1" {if $Think.get.share eq 1} selected {/if}>当前公司</option>
                <option value="2" {if $Think.get.share eq 2} selected {/if}>公共资源</option>
            </select>
        </div>

        <button class="layui-btn layui-btn-sm" onclick="search()">
            <i class="layui-icon layui-icon-search"></i>搜索
        </button>
        <span class="x-right">共有数据:<i class="i_count">{$product->total()}</i>条
            <button onclick="javascript:location.reload()" class="layui-btn-default ">
                <i class="layui-icon layui-icon-refresh"></i>
            </button>
        </span>
    </div>


    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 30px;text-align:center">
            </th>
            <th style="width:100px;text-align:center">产品图</th>
            <th>产品标题</th>
            <th style="width: 80px;text-align:center">售价</th>
            <th style="min-width: 80px;text-align:center">SKU码</th>
            <th style="width: 60px;text-align:center">分类</th>
            <th style="width: 60px;text-align:center">平台</th>
            <th style="width: 60px;text-align:center">分享用户</th>
            {if $Think.get.share == ''}
            <th style="width: 60px;text-align:center">数据来源</th>
            {/if}
            <th style="width: 115px;text-align:center">加入时间</th>
            <th style="width: 135px;text-align:center">操作</th>
        </thead>
        <tbody>

        {volist name="product" id="vo"}
        <tr>
            <td style="text-align:center">
                {$i}
            </td>
            <td style="text-align:center">
                {if isset($resources[$vo['id']]['path'])}
                <img src="{$resources[$vo['id']]['path']}" onclick="previewImg(this)">
                {else/}
                <img src="__images__/noimg.png">
                {/if}
            </td>
            <td>
                {if !empty($vo['fromurl'])}
                <a href="{$vo.fromurl}" style="color: #01AAED;" target="_blank">{$vo.proname}</a>
                {else/}
                {$vo.proname}
                {/if}
            </td>
            <td style="text-align:center">{$vo.coin}{$vo.saleprice}</td>
            <td style="text-align:center">{$vo.skucode}</td>
            <td style="text-align:center">{$vo.catename}</td>
            <td style="text-align:center">{$vo.platform}</td>
            <td style="text-align:center">{$vo.truename}</td>
            {if $Think.get.share == ''}
            <th style="text-align:center">
                {switch name="$vo.share" }
                {case value="1"}当前公司{/case}
                {case value="2"}公共资源{/case}
                {/switch}
            </th>
            {/if}
            <td style="text-align:center">{$vo['timestamp']|date="Y-m-d H:i",###}</td>
            <td class="caozuo">
                <button class="layui-btn layui-btn-xs  layui-btn-normal"
                        onclick="x_admin_show('详情','productShareInfo.html?id={$vo.id}')">详情
                </button>

                <button class="layui-btn layui-btn-xs layui-btn-warm"
                        onclick="uploadShare('{$vo.id}')">一键导入
                </button>

                {if $vo.user_id eq isession('user_id')}
                <button onclick="del(this,'{$vo.id}')" class="layui-btn layui-btn-xs layui-btn-danger">删除</button>
                {/if}
            </td>
        </tr>
        {/volist}

        </tbody>
    </table>
    <div class="page">
        <div>
            {$product->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    var layer = layui.layer;

    function search() {
        var proname = $("#proname").val();
        var code = $("#code").val();
        var platform = $("#platform").val();
        var share = $("#share").val();
        location.href = "productListShare.html?proname=" + proname + "&code=" + code + "&platform=" + platform+ "&share=" + share;
    }

    function del(obj, id) {
        var count = $(".i_count")[0].innerText;
        layer.confirm('确认要删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/product/deleteShare')}", {id: id}, function (data) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(obj).parents('tr').remove();
                        $(".i_count").html(count - 1);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    function uploadShare(id) {
        layer.confirm('确认将该产品导入个人产品库？', function (index) {
            // layer.load(1);
            $.post("{:url('admin/product/uploadShare')}", {id: id}, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.alert(data.msg, {icon: 1},function(){
                        location.reload();
                    });
                } else {
                    layer.alert(data.msg, {icon: 2, time: 1000});
                }
            });
        });
    }
</script>
